<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>
<script>
	import {
		getSignatureInfo
	} from '@/api/login';
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		mounted() {
			window.addEventListener("load", () => {
				//页面手动刷新后，需要重新鉴权
				console.log("我被刷新了");
			 getApp().ddPermission();
		 });
		},
		methods: {
			// 钉钉鉴权--全局引用
			ddPermission() {
				let that = this;
				var url = uni.getStorageSync('permission_url');
				var jsapilist = [
					'device.notification.alert', //警告框
					'device.notification.confirm', //确认框
					'biz.navigation.setTitle', //设置导航栏标题
					'biz.navigation.quit', //关闭页面
					'biz.util.openModal', //打开弹窗（模态窗）
					'biz.contact.complexPicker', //选择人员
					'device.geolocation.get', //获取当前地理位置信息
					'biz.map.locate', //地图定位
					'biz.map.search', //地图页面支持搜索
					'biz.map.view' //展示位置
				]; //需要使用的jsapi列表
				// 鉴权有效期是2小时，如果鉴权还没过期（提前10分钟），就直接拿本地的数据，如果过期了，再服务器上拿
				if (uni.getStorageSync('endStamp') && uni.getStorageSync('endStamp') - Date.now() > 10 * 60 * 1000) {
					//1、鉴权
					window.dd.config({
						agentId: uni.getStorageSync('_config.agentId'),
						corpId: uni.getStorageSync('_config.corpId'), //必填，企业ID
						timeStamp: uni.getStorageSync('_config.timeStamp'), // 必填，生成签名的时间戳
						nonceStr: uni.getStorageSync('_config.nonceStr'), // 必填，生成签名的随机串
						signature: uni.getStorageSync('_config.signature'), // 必填，签名
						jsApiList: jsapilist // 必填，需要使用的jsapi列表，注意：不要带dd。
					});

					window.dd.error(function(err) { //验证失败  
						console.log("进入到error中1");
						console.log('dd error: ' + JSON.stringify(err));
					})
				} else {
					getSignatureInfo(url).then(res => {
						console.log("重新鉴权成功");
						const _config = res.data
						var endStamp = Date.now() + 2 * 60 * 60 * 1000;
						// 鉴权有效期2小时，将返回的信息存在本地，在有效期内避免多次访问后台获取
						uni.setStorageSync('endStamp', endStamp);
						uni.setStorageSync('_config.agentId', _config.agentId);
						uni.setStorageSync('_config.corpId', _config.corpId);
						uni.setStorageSync('_config.timeStamp', _config.timeStamp);
						uni.setStorageSync('_config.nonceStr', _config.nonceStr);
						uni.setStorageSync('_config.signature', _config.signature);
						//1、鉴权
						window.dd.config({
							agentId: _config.agentId,
							corpId: _config.corpId, //必填，企业ID
							timeStamp: _config.timeStamp, // 必填，生成签名的时间戳
							nonceStr: _config.nonceStr, // 必填，生成签名的随机串
							signature: _config.signature, // 必填，签名
							jsApiList: jsapilist // 必填，需要使用的jsapi列表，注意：不要带dd。
						});

						window.dd.error(function(err) { //验证失败  
							console.log("进入到error中");
							console.log('dd error: ' + JSON.stringify(err));
						})
					});
				}

			},

		}
	}
</script>
<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 30rpx;
		line-height: inherit;
	}

	.pt5 {
		padding-top: 10rpx;
	}

	.pr5 {
		padding-right: 10rpx;
	}

	.pb5 {
		padding-bottom: 10rpx;
	}

	.mt5 {
		margin-top: 10rpx;
	}

	.mr5 {
		margin-right: 10rpx;
	}

	.mb5 {
		margin-bottom: 10rpx;
	}

	.ml5 {
		margin-left: 10rpx;
	}

	.mt10 {
		margin-top: 20rpx;
	}

	.mr10 {
		margin-right: 20rpx;
	}

	.mb10 {
		margin-bottom: 20rpx;
	}

	.ml0 {
		margin-left: 20rpx;
	}

	.mt20 {
		margin-top: 40rpx;
	}

	.mr20 {
		margin-right: 40rpx;
	}

	.mb20 {
		margin-bottom: 40rpx;
	}

	.m20 {
		margin-left: 40rpx;
	}

	.ui-all {
		padding: 20rpx 40rpx;

		.avatar {
			width: 100%;
			text-align: left;
			padding: 20rpx 0;
			border-bottom: solid 1rpx #f2f2f2;
			position: relative;

			.imgAvatar {
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
				display: inline-block;
				vertical-align: middle;
				overflow: hidden;

				.iavatar {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			text {
				display: inline-block;
				vertical-align: middle;
				color: #8e8e93;
				font-size: 28rpx;
				margin-left: 40rpx;
			}

			&:after {
				content: ' ';
				width: 20rpx;
				height: 20rpx;
				border-top: solid 1rpx #030303;
				border-right: solid 1rpx #030303;
				transform: rotate(45deg);
				-ms-transform: rotate(45deg);
				/* IE 9 */
				-moz-transform: rotate(45deg);
				/* Firefox */
				-webkit-transform: rotate(45deg);
				/* Safari 和 Chrome */
				-o-transform: rotate(45deg);
				position: absolute;
				top: 85rpx;
				right: 0;
			}
		}

		.ui-list {
			width: 100%;
			text-align: left;
			padding: 20rpx 0;
			border-bottom: solid 1rpx #f2f2f2;
			position: relative;

			text {
				color: #4a4a4a;
				font-size: 28rpx;
				display: inline-block;
				vertical-align: middle;
				width: 150rpx;
			}

			uni-radio-group {
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				background: none;
				margin: 0;
				padding: 0;
			}

			input {
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				left: 150rpx;
				width: calc(100% - 150rpx);
			}

			button {
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				background: none;
				width: calc(100% - 150rpx);
				margin: 0;
				text-align: left;
				padding: 0;
				height: 30rpx;
				line-height: 30rpx;

				&::after {
					display: none;
				}
			}

			picker {
				width: calc(100% - 150rpx);
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				position: absolute;
				left: 150rpx;
				top: 25rpx;
			}

			.continer {
				width: calc(100% - 150rpx);
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				left: 150rpx;
			}

			textarea {
				color: #030303;
				font-size: 30rpx;
				vertical-align: middle;
				height: 150rpx;
				width: 100%;
				margin-top: 50rpx;
				left: 150rpx;
			}
		}

		.right:after {
			content: ' ';
			width: 20rpx;
			height: 20rpx;
			border-top: solid 1rpx #030303;
			border-right: solid 1rpx #030303;
			transform: rotate(45deg);
			-ms-transform: rotate(45deg);
			/* IE 9 */
			-moz-transform: rotate(45deg);
			/* Firefox */
			-webkit-transform: rotate(45deg);
			/* Safari 和 Chrome */
			-o-transform: rotate(45deg);
			position: absolute;
			top: 30rpx;
			right: 0;
		}

		.input-body {
			width: 90%;
			color: #030303;
			font-size: 30rpx;
			display: inline-block;
			vertical-align: middle;
			position: absolute;
			top: 30rpx;
			left: 150rpx;
		}

		.save {
			background: #030303;
			border: none;
			color: #ffffff;
			margin-top: 40rpx;
			font-size: 28rpx;
		}

	}

	.u-form-item__body {
		display: flex;
		flex-direction: row;
		padding: 6px 0 !important;
	}
</style>
